<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>class的继承</title>
</head>
<body>

</body>
<script>
    {
        //ES5写法
        function Phone(brand,price) {
            this.brand = brand;
            this.price = price;
        }

        Phone.prototype.call=function (){
            console.log('我能够打电话~');
        }

        function SmartPhone(brand,price,coler,size){
            Phone.call(this,brand,price);
            this.coler=coler;
            this.size=size;
        }

        //设置子级构造函数原型
        SmartPhone.prototype = new Phone;
        SmartPhone.prototype.constructor = SmartPhone;

        //子类方法
        SmartPhone.prototype.playGame = function (){
            console.log('我能打游戏');
        }

        console.log(new SmartPhone('苹果',19999,'red','5.7'));
    }

    //ES6 class写法
    {
        class Phone{
            constructor(brand,price) {
                this.brand = brand;
                this.price = price;
            }
            call(){
                console.log('打电话');
            }
        }


        class SmartPhone extends Phone{
            constructor(brand,price,coler,size) {
                super(brand,price);
                this.coler = coler;
                this.size = size;
            }
            playGame(){
                console.log('我能打游戏');
            }

            //子类无法获取到父类的方法，因此在ES6中只能重写父类的方法
            call(){
                console.log('我重写了打点电话');
            }

        }

        let iPhone = new SmartPhone('iPhone',9999,'red',5.7);
        console.log(iPhone);

    }
</script>
</html>